#! /usr/bin/env python
# -*- coding: utf-8 -*-
import redis
from django.conf import settings
# 直接连接redis

conn = redis.Redis(host=settings.HOST_REDIS, port=settings.PORT_REDIS,
                   password=settings.PASSWORD_REDIS, encoding='utf-8')


def set_value(key, value, ex=None, *args, **kwargs):
    conn.set(key, value, ex, *args, **kwargs)


def get_value(key):
    val = conn.get(key)
    if val:
        return str(val, encoding='utf-8')
    return val


